<?php

	class Home extends  CI_Controller{
		function __construct()
		{
			parent::__construct();
			$this->load->helper("url");
		}	
		
		function index()
		{
			$this->load->model("Madmin");
			$data["courseware_list"] = $this->Madmin->get_courseware_list();
			$this->load->view("home",$data);
		}
		
		function courseware()
		{
			$this->load->model("Madmin");
			$data["courseware"] = $this->Madmin->get_courseware($this->uri->segment(3));
			$this->load->view("courseware",$data);
		}
		
		function exam()
		{
			$this->load->model("Madmin");
			$data["exam"] = $this->Madmin->get_exam($this->uri->segment(3));
			foreach ($data["exam"] as $row)
			{
				$data["exam_answer"][$row->id] = $this->Madmin->get_exam_answer($row->id);
			}
			$this->load->view("exam",$data);
		}
		
		function do_exam_ok()
		{
			$this->load->model("Madmin");
			$question = $this->Madmin->get_exam($this->uri->segment(3));
			$i = 0;
			foreach ( $question as $row )
			{
				$data["answer_result"][$row->id] = $this->Madmin->do_exam($row->id,$this->input->post("answer_".$row->id));
			}
			$dbdata["coursewareid"] = $this->uri->segment(3);
			$dbdata["rightnum"] = 0;
			foreach ($data["answer_result"] as $row_result)
			{
				if ($row_result[0]->nums==1) $dbdata["rightnum"]++;
			}
			$data["homework"] = $this->Madmin->get_homework($dbdata);
			$this->load->view("exam_result",$data);
		}
	}